/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import Shopping.Connect;
import Shopping.Goods;
import Shopping.ShopcartJTable;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


/**
 *
 * @author Administrator
 */
public class Shop extends javax.swing.JFrame {


    /**
     * Creates new form Shop
     */
    public Shop() {
        initComponents();
        jPanel1Display();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialogModify = new javax.swing.JDialog();
        jLabel24 = new javax.swing.JLabel();
        jTextFieldname = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jTextFieldcount = new javax.swing.JTextField();
        jButtonCheck = new javax.swing.JButton();
        jDialogPay = new javax.swing.JDialog();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jButtonMai = new javax.swing.JButton();
        jTextFieldSum = new javax.swing.JTextField();
        jTextFieldSum2 = new javax.swing.JTextField();
        jFrameCart = new javax.swing.JFrame();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButtonModify = new javax.swing.JButton();
        jButtonDelete = new javax.swing.JButton();
        jButtonClear = new javax.swing.JButton();
        jButtonPay = new javax.swing.JButton();
        jButtonReturn = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxList = new javax.swing.JComboBox<>();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jTextFieldCount = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jButtonAdd = new javax.swing.JButton();
        jButtonLook = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        jDialogModify.setMinimumSize(new java.awt.Dimension(221, 149));

        jLabel24.setText("请输入要修改的商品名称：");

        jTextFieldname.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldnameActionPerformed(evt);
            }
        });

        jLabel25.setText("请输入要购买的数量：");

        jTextFieldcount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldcountActionPerformed(evt);
            }
        });

        jButtonCheck.setText("确认");
        jButtonCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCheckActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDialogModifyLayout = new javax.swing.GroupLayout(jDialogModify.getContentPane());
        jDialogModify.getContentPane().setLayout(jDialogModifyLayout);
        jDialogModifyLayout.setHorizontalGroup(
            jDialogModifyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogModifyLayout.createSequentialGroup()
                .addGroup(jDialogModifyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDialogModifyLayout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(jDialogModifyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel25)
                            .addComponent(jLabel24, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTextFieldname)
                            .addComponent(jTextFieldcount)))
                    .addGroup(jDialogModifyLayout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addComponent(jButtonCheck)))
                .addContainerGap(36, Short.MAX_VALUE))
        );
        jDialogModifyLayout.setVerticalGroup(
            jDialogModifyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogModifyLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel24)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel25)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldcount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(jButtonCheck)
                .addContainerGap())
        );

        jDialogPay.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jDialogPay.setAlwaysOnTop(true);

        jLabel23.setText("总计：");

        jLabel26.setText("您一共需支付");

        jButtonMai.setText("支付");
        jButtonMai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMaiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDialogPayLayout = new javax.swing.GroupLayout(jDialogPay.getContentPane());
        jDialogPay.getContentPane().setLayout(jDialogPayLayout);
        jDialogPayLayout.setHorizontalGroup(
            jDialogPayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogPayLayout.createSequentialGroup()
                .addGroup(jDialogPayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDialogPayLayout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(jButtonMai))
                    .addGroup(jDialogPayLayout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(jLabel23)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldSum, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jDialogPayLayout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel26)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFieldSum2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        jDialogPayLayout.setVerticalGroup(
            jDialogPayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogPayLayout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(jDialogPayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jDialogPayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel23)
                        .addComponent(jTextFieldSum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jDialogPayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel26)
                    .addComponent(jTextFieldSum2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButtonMai)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jFrameCart.setMinimumSize(new java.awt.Dimension(481, 346));
        jFrameCart.setName("购物车"); // NOI18N
        jFrameCart.setSize(new java.awt.Dimension(0, 0));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "商品ID", "商品名", "单价", "数量"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTable1.setColumnSelectionAllowed(true);
        jScrollPane2.setViewportView(jTable1);

        jButtonModify.setText("更改");
        jButtonModify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonModifyActionPerformed(evt);
            }
        });

        jButtonDelete.setText("删除");
        jButtonDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDeleteActionPerformed(evt);
            }
        });

        jButtonClear.setText("清空");
        jButtonClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClearActionPerformed(evt);
            }
        });

        jButtonPay.setText("结算");
        jButtonPay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPayActionPerformed(evt);
            }
        });

        jButtonReturn.setText("返回");
        jButtonReturn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonReturnActionPerformed(evt);
            }
        });

        jButtonExit.setText("退出");
        jButtonExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jFrameCartLayout = new javax.swing.GroupLayout(jFrameCart.getContentPane());
        jFrameCart.getContentPane().setLayout(jFrameCartLayout);
        jFrameCartLayout.setHorizontalGroup(
            jFrameCartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jFrameCartLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jButtonModify)
                .addGap(18, 18, 18)
                .addComponent(jButtonDelete)
                .addGap(18, 18, 18)
                .addComponent(jButtonClear)
                .addGap(18, 18, 18)
                .addComponent(jButtonPay)
                .addGap(18, 18, 18)
                .addComponent(jButtonReturn)
                .addGap(18, 18, 18)
                .addComponent(jButtonExit)
                .addContainerGap(26, Short.MAX_VALUE))
            .addComponent(jScrollPane2)
        );
        jFrameCartLayout.setVerticalGroup(
            jFrameCartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jFrameCartLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jFrameCartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonModify)
                    .addComponent(jButtonDelete)
                    .addComponent(jButtonClear)
                    .addComponent(jButtonPay)
                    .addComponent(jButtonReturn)
                    .addComponent(jButtonExit))
                .addGap(0, 32, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });

        jLabel1.setText("商品ID");

        jLabel2.setText("商品名");

        jLabel3.setText("价格");

        jComboBoxList.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Java", "Math", "短裙", "夹克", "牛奶" }));
        jComboBoxList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxListActionPerformed(evt);
            }
        });

        jLabel19.setText("选择要购买的商品");

        jLabel20.setText("商品数量");

        jTextFieldCount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCountActionPerformed(evt);
            }
        });

        jLabel21.setText("件");

        jButtonAdd.setText("加入购物车");
        jButtonAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddActionPerformed(evt);
            }
        });

        jButtonLook.setText("查看购物车");
        jButtonLook.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLookActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(105, 105, 105)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel20)
                            .addComponent(jLabel19))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jComboBoxList, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTextFieldCount))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel21))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(87, 87, 87)
                        .addComponent(jLabel1)
                        .addGap(77, 77, 77)
                        .addComponent(jLabel2)
                        .addGap(81, 81, 81)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonLook)
                    .addComponent(jButtonAdd))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(62, 62, 62)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(jButtonAdd))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel20)
                            .addComponent(jTextFieldCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel21))
                        .addContainerGap(20, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                        .addComponent(jButtonLook)
                        .addContainerGap())))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldCountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCountActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCountActionPerformed

    private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
        // TODO add your handling code here:    
        ShopcartJTable sj=new ShopcartJTable(jTable1);
        if(sj.Addgoods(jComboBoxList.getItemAt(jComboBoxList.getSelectedIndex()),Integer.parseInt(jTextFieldCount.getText())))
            JOptionPane.showMessageDialog(null, "添加成功");
        else
            JOptionPane.showMessageDialog(null, "添加失败");
    }//GEN-LAST:event_jButtonAddActionPerformed

    private void jComboBoxListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxListActionPerformed
        // TODO add your handling code here:
      
    }//GEN-LAST:event_jComboBoxListActionPerformed

    private void jButtonLookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLookActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        jFrameCart.setVisible(true);
        jFrameCart.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }//GEN-LAST:event_jButtonLookActionPerformed

    private void jButtonCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCheckActionPerformed
        // TODO add your handling code here:
        ShopcartJTable sj=new ShopcartJTable(jTable1);
        if(sj.Addgoods(jTextFieldname.getText(), Integer.parseInt(jTextFieldcount.getText())))
             JOptionPane.showMessageDialog(null, "修改成功");
        else
            JOptionPane.showMessageDialog(null, "修改失败");
        jDialogModify.setVisible(false);
    }//GEN-LAST:event_jButtonCheckActionPerformed

    private void jTextFieldnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldnameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldnameActionPerformed

    private void jTextFieldcountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldcountActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldcountActionPerformed

    private void jButtonMaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMaiActionPerformed
        // TODO add your handling code here:
        ShopcartJTable sj=new ShopcartJTable(jTable1);
        if(sj.Cleargoods())
            JOptionPane.showMessageDialog(null, "支付成功");
        else
            JOptionPane.showMessageDialog(null, "支付失败");
        jDialogPay.setDefaultCloseOperation((int)evt.getSource());
    }//GEN-LAST:event_jButtonMaiActionPerformed

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_formMouseClicked

    private void jButtonModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyActionPerformed
        // TODO add your handling code here:
        ShopcartJTable sj=new ShopcartJTable(jTable1);
        int rowIndex = jTable1.getSelectedRow();
        if(rowIndex!=-1){
            sj.Delgoods(rowIndex);
            jDialogModify.setVisible(true);
            jDialogModify.pack();
        }else{
            JOptionPane.showMessageDialog(null, "未选择");   
        }
        
    }//GEN-LAST:event_jButtonModifyActionPerformed

    private void jButtonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteActionPerformed
        // TODO add your handling code here:
        ShopcartJTable sj=new ShopcartJTable(jTable1);
        int rowIndex = jTable1.getSelectedRow();
        if(rowIndex!=-1){
            if(sj.Delgoods(rowIndex))
                JOptionPane.showMessageDialog(null, "删除成功");  
            else
                JOptionPane.showMessageDialog(null, "删除失败");  
        }else{
            JOptionPane.showMessageDialog(null, "未选择");   
        }
    }//GEN-LAST:event_jButtonDeleteActionPerformed

    private void jButtonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClearActionPerformed
        // TODO add your handling code here:
        ShopcartJTable sj=new ShopcartJTable(jTable1);
        if(sj.Cleargoods())
            JOptionPane.showMessageDialog(null, "清空成功");  
        else
            JOptionPane.showMessageDialog(null, "清空失败"); 
    }//GEN-LAST:event_jButtonClearActionPerformed

    private void jButtonPayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPayActionPerformed
        // TODO add your handling code here:
        ShopcartJTable sj=new ShopcartJTable(jTable1);
        double sum=sj.Sum();
        if(sum!=0){
        jTextFieldSum.setText(String.valueOf(sum)+" 元");
        jTextFieldSum2.setText(String.valueOf(sum)+" 元");
        jDialogPay.setVisible(true);
        jDialogPay.pack();
        jDialogPay.setDefaultCloseOperation(evt.getModifiers());
        jDialogModify.setVisible(false);
        }
        else
            JOptionPane.showMessageDialog(null, "无任何商品"); 
    }//GEN-LAST:event_jButtonPayActionPerformed

    private void jButtonReturnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReturnActionPerformed
        // TODO add your handling code here:S
        jFrameCart.dispose();
        this.setVisible(true);
    }//GEN-LAST:event_jButtonReturnActionPerformed

    private void jButtonExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExitActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jButtonExitActionPerformed
    private void jPanel1Display() { 
    ArrayList<Goods> list=new Connect().getAllgoods();
        jTextArea1.setText("");
        for(Goods e:list){
            jTextArea1.setText("\t"+e.getId()+"\t"+e.getName()+"\t"+e.getPrice()+"\n");
            System.out.println(e);
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Shop.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Shop.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Shop.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Shop.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {
            new Shop().setVisible(true);
        });
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdd;
    private javax.swing.JButton jButtonCheck;
    private javax.swing.JButton jButtonClear;
    private javax.swing.JButton jButtonDelete;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonLook;
    private javax.swing.JButton jButtonMai;
    private javax.swing.JButton jButtonModify;
    private javax.swing.JButton jButtonPay;
    private javax.swing.JButton jButtonReturn;
    private javax.swing.JComboBox<String> jComboBoxList;
    private javax.swing.JDialog jDialogModify;
    private javax.swing.JDialog jDialogPay;
    private javax.swing.JFrame jFrameCart;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextFieldCount;
    private javax.swing.JTextField jTextFieldSum;
    private javax.swing.JTextField jTextFieldSum2;
    private javax.swing.JTextField jTextFieldcount;
    private javax.swing.JTextField jTextFieldname;
    // End of variables declaration//GEN-END:variables

   
}
